package com.mcxx.util;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;


@Data
@ApiModel(value="接口返回对象", description="接口返回对象")
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "成功标志")
    private boolean success = true;


    @ApiModelProperty(value = "返回处理消息")
    private String desc = "操作成功！";


    @ApiModelProperty(value = "返回代码")
    private Integer code = 0;


    @ApiModelProperty(value = "返回银行账号信息")
    private String accountid = "";


    @ApiModelProperty(value = "返回补贴对象信息")
    private String objectid = "";


    @ApiModelProperty(value = "返回家庭成员信息")
    private String memberid = "";


    @ApiModelProperty(value = "判断补贴对象是否存在（0不存在，1存在）")
    private String resultExist;


    @ApiModelProperty(value = "返回数据对象")
    private T data;


    @ApiModelProperty(value = "时间戳")
    private long timestamp = System.currentTimeMillis();

    public Result() {
        code = 1;
        desc = "success";
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.desc = msg;
    }

    public Result<T> success(String message) {
        this.desc = message;
        this.code = 200;
        this.success = true;
        return this;
    }


    public static Result<Object> ok() {
        Result<Object> r = new Result<Object>();
        r.setSuccess(true);
        r.setCode(200);
        r.setDesc("成功");
        return r;
    }

    public static Result<Object> ok(String msg) {
        Result<Object> r = new Result<Object>();
        r.setSuccess(true);
        r.setCode(200);
        r.setDesc(msg);
        return r;
    }

    public static Result<Object> ok(Object data) {
        Result<Object> r = new Result<Object>();
        r.setSuccess(true);
        r.setCode(200);
        r.setData(data);
        return r;
    }

    public static Result<Object> error(String msg) {
        return error(500, msg);
    }

    public static Result<Object> error(int code, String msg) {
        Result<Object> r = new Result<Object>();
        r.setCode(code);
        r.setDesc(msg);
        r.setSuccess(false);
        return r;
    }

    public Result<T> error500(String message) {
        this.desc = message;
        this.code = 500;
        this.success = false;
        return this;
    }
}
